package com.hxx.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hxx.entity.TrainCarriageEntity;
import com.hxx.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.hxx.service.TrainCarriageService;

@RestController
@RequestMapping("/trainCarriage")
public class TrainCarriageController {
    @Autowired
    private TrainCarriageService trainCarriageService;

    @GetMapping("page")
    public R listPage(Page page, TrainCarriageEntity trainCarriage) {
        trainCarriageService.listPage(page, trainCarriage);
        return R.ok().data("list", page.getRecords())
                .data("total", page.getTotal());
    }

    @PostMapping("save")
    public R add(@RequestBody TrainCarriageEntity trainCarriage) {
        trainCarriageService.save(trainCarriage);
        return R.ok();
    }

    @PutMapping("update")
    public R update(@RequestBody TrainCarriageEntity trainCarriage) {
        trainCarriageService.updateById(trainCarriage);
        return R.ok();
    }

    @DeleteMapping("delete/{id}")
    public R delete(@PathVariable Long id) {
        trainCarriageService.removeById(id);
        return R.ok();
    }
}
























